package netbay;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.util.Properties;

import netbayServlet.AddAdminServlet;
import netbayServlet.RDBilling;
import netbayServlet.TCDBillingServlet;
import netbayServlet.ViewServlet;
import netbayServlet.ViewServletRD;

public class NetbayUtility {

	private static boolean isInit = false;

	public static void init(String configPath){
		if (!isInit) {

			Properties prop = new Properties();
			FileInputStream fis = null;;
			Reader readIn = null;
			try {
				fis = new FileInputStream(configPath);
				readIn = new InputStreamReader(fis, "UTF-8");
			} catch (FileNotFoundException e2) {
				System.out.println("Can't find the properties.xml.");
				return;
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
			try {
				prop.load(readIn);
			} catch (IOException e1) {
				e1.printStackTrace();
			}
			prop.list(System.out);
			
			WorkerManager.TCDRecvCmd = prop.getProperty("TCDRecvCmd");
			WorkerManager.JPMCRecvCmd = prop.getProperty("JPMCRecvCmd");
			WorkerManager.UpdateDbCmd = prop.getProperty("UpdateDbCmd");
			WorkerManager.testCmd = prop.getProperty("testCmd");
			WorkerManager.reTCDTCDCmd = prop.getProperty("reTCDTCDCmd");
			WorkerManager.reJPMCTCDCmd = prop.getProperty("reJPMCTCDCmd");
			
			WorkerManager.NetbayTrackUrl = prop.getProperty("NetbayTrackUrl");
			WorkerManager.NetbayTrackUser = prop.getProperty("NetbayTrackUser");
			WorkerManager.NetbayTrackPassword = prop.getProperty("NetbayTrackPassword");
			WorkerManager.NetbayTrackDocType = prop.getProperty("NetbayTrackDocType");
			WorkerManager.NetbayTrackKeyGet = prop.getProperty("NetbayTrackKeyGet");
			
			WorkerManager.RDPostUrl = prop.getProperty("RDPostUrl");
			
			WorkerManager.SFTPrecvPath = prop.getProperty("SFTPrecvPath");
			
			WorkerManager.TCDRecvDir = prop.getProperty("TCDRecvDir");
			WorkerManager.JPMCRecvDir = prop.getProperty("JPMCRecvDir");
			WorkerManager.JPMCDesDir = prop.getProperty("JPMCDesDir");
			WorkerManager.ActionTCDToBank = prop.getProperty("ActionTCDToBank");
			WorkerManager.ActionBankToTCD = prop.getProperty("ActionBankToTCD");
			WorkerManager.ActionRDToBank = prop.getProperty("ActionRDToBank");
			WorkerManager.ActionBankToRD = prop.getProperty("ActionBankToRD");
			
			SFTPManager.sftpRetryChance = Integer.parseInt(prop.getProperty("sftpRetryChance"));
			SFTPManager.sftpRetryDelay = Integer.parseInt(prop.getProperty("sftpRetryDelay"));
			
			SFTPManager.SFTPuser = prop.getProperty("SFTPuser");
			SFTPManager.SFTPhost = prop.getProperty("SFTPhost");
			SFTPManager.SFTPport = Integer.parseInt(prop.getProperty("SFTPPort"));
			SFTPManager.SFTPprivateKeyPath = prop.getProperty("SFTPprivateKeyPath");
			SFTPManager.SFTPpassPhrase = prop.getProperty("SFTPpassPhrase");
			SFTPManager.SFTPknowHostStrict = prop.getProperty("SFTPknowHostStrict").equalsIgnoreCase("true");
			
			SFTPManager.SFTPsendPath = prop.getProperty("SFTPsendPath");
			SFTPManager.SFTPrecvPath = prop.getProperty("SFTPrecvPath");
			
			TransactionManager.recvTcdStatus = prop.getProperty("recvTcdStatus");
			TransactionManager.beginSendJpmcStatus = prop.getProperty("beginSendJpmcStatus");
			TransactionManager.finSendJpmcStatus = prop.getProperty("finSendJpmcStatus");
			TransactionManager.recvJpmcStatus = prop.getProperty("recvJpmcStatus");
			TransactionManager.sendTcdStatus = prop.getProperty("sendTcdStatus");
			TransactionManager.finSendTcdStatus = prop.getProperty("finSendTcdStatus");
			TransactionManager.resendSFTPStatus = prop.getProperty("resendSFTPStatus");
			TransactionManager.resendFinSFTPStatus = prop.getProperty("resendFinSFTPStatus");
			TransactionManager.redownloadSFTPStatus = prop.getProperty("redownloadSFTPStatus");
			TransactionManager.redownloadFinSFTPStatus = prop.getProperty("redownloadFinSFTPStatus");

			TransactionManager.recvRdStatus = prop.getProperty("recvRdStatus");
			TransactionManager.beginSendJpmcStatusRD = prop.getProperty("beginSendJpmcStatusRD");
			TransactionManager.finSendJpmcStatusRD = prop.getProperty("finSendJpmcStatusRD");
			TransactionManager.recvJpmcStatusRD = prop.getProperty("recvJpmcStatusRD");
			TransactionManager.sendRdStatus = prop.getProperty("sendRdStatus");
			TransactionManager.finSendRdStatus = prop.getProperty("finSendRdStatus");
			TransactionManager.resendSFTPStatusRD = prop.getProperty("resendSFTPStatusRD");
			TransactionManager.resendFinSFTPStatusRD = prop.getProperty("resendFinSFTPStatusRD");
			TransactionManager.redownloadSFTPStatusRD = prop.getProperty("redownloadSFTPStatusRD");
			TransactionManager.redownloadFinSFTPStatusRD = prop.getProperty("redownloadFinSFTPStatusRD");

			TransactionManager.dbUrl = prop.getProperty("dbUrl");
			TransactionManager.dbUser = prop.getProperty("dbUser");
			TransactionManager.dbPassword = prop.getProperty("dbPassword");
			TransactionManager.jdbcDriver = prop.getProperty("jdbcDriver");
			
			UserManager.dbUrl = prop.getProperty("dbUrl");
			UserManager.dbUser = prop.getProperty("dbUser");
			UserManager.dbPassword = prop.getProperty("dbPassword");
			UserManager.jdbcDriver = prop.getProperty("jdbcDriver");
			UserManager.superAdmin = prop.getProperty("superAdmin");
			UserManager.passwordSuperAdmin = prop.getProperty("passwordSuperAdmin");
			UserManager.isAble = prop.getProperty("isAble");
			UserManager.actionLogin = prop.getProperty("actionLogin");
			UserManager.actionLogout = prop.getProperty("actionLogout");
			UserManager.actionEditGroup = prop.getProperty("actionEditGroup");
			UserManager.actionDeleteGroup = prop.getProperty("actionDeleteGroup");
			UserManager.actionAddNewGroup = prop.getProperty("actionAddNewGroup");
			UserManager.actionAddNewUser = prop.getProperty("actionAddNewUser");
			UserManager.actionEditUser = prop.getProperty("actionEditUser");
			UserManager.actionDeleteUser = prop.getProperty("actionDeleteUser");
			UserManager.actionEditProfile = prop.getProperty("actionEditProfile");
			UserManager.actionReTCDTCD = prop.getProperty("actionReTCDTCD");
			UserManager.actionReJPMCTCD = prop.getProperty("actionReJPMCTCD");
			UserManager.actionReRDRD = prop.getProperty("actionReRDRD");
			UserManager.actionReJPMCRD = prop.getProperty("actionReJPMCRD");


			
			AddAdminServlet.superAdmin = prop.getProperty("superAdmin");
			TCDBillingServlet.ratePerTransaction = prop.getProperty("ratePerTransaction");
			RDBilling.ratePerTransactionRd = prop.getProperty("ratePerTransactionRd");
			ViewServlet.recvTcdStatus = prop.getProperty("recvTcdStatus");
			ViewServlet.beginSendJpmcStatus = prop.getProperty("beginSendJpmcStatus");
			ViewServlet.finSendJpmcStatus = prop.getProperty("finSendJpmcStatus");
			ViewServlet.recvJpmcStatus = prop.getProperty("recvJpmcStatus");
			ViewServlet.sendTcdStatus = prop.getProperty("sendTcdStatus");
			ViewServlet.finSendTcdStatus = prop.getProperty("finSendTcdStatus");
			
			ViewServletRD.recvRdStatus = prop.getProperty("recvRdStatus");
			ViewServletRD.beginSendJpmcStatus = prop.getProperty("beginSendJpmcStatusRD");
			ViewServletRD.finSendJpmcStatus = prop.getProperty("finSendJpmcStatusRD");
			ViewServletRD.recvJpmcStatus = prop.getProperty("recvJpmcStatusRD");
			ViewServletRD.sendRdStatus = prop.getProperty("sendRdStatus");
			ViewServletRD.finSendRdStatus = prop.getProperty("finSendRdStatus");
			
			TransactionManager.JPMCcpaId = prop.getProperty("JPMCcpaId");
			TransactionManager.JPMCService = prop.getProperty("JPMCService");
			TransactionManager.JPMCTransportProtocol = prop.getProperty("JPMCTransportProtocol");
			TransactionManager.JPMCTransportEndPoint = prop.getProperty("JPMCTransportEndPoint");
			TransactionManager.JPMCPayloadType = prop.getProperty("JPMCPayloadType");
			
			isInit = true;
		}
	}
}
